package band.wukong.practice.javase.core.io.stream;

import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.FileInputStream;
import java.io.FileOutputStream;

public class TestDataStream {
    
    public static void main(String[] args) throws Exception {
        FileOutputStream fo = new FileOutputStream("1.dat");
        DataOutputStream out = new DataOutputStream(fo);
        /*
           * String s="Tarena"; byte[] bs=s.getBytes(); fo.write(bs);
           */
        byte b = 10;
        short s = 1234;
        int i = 123456789;
        long l = 1234567890123456L;
        float f = 1.3f;
        double d = 2.6;
        String str = "Hello Tarena";

        out.writeByte(b);
        out.writeShort(s);
        out.writeInt(i);
        out.writeLong(l);
        out.writeFloat(f);
        out.writeDouble(d);
        out.writeUTF(str);

        out.close();

        FileInputStream fi = new FileInputStream("1.dat");
        DataInputStream in = new DataInputStream(fi);

        System.out.println(in.readShort());
        System.out.println(in.readByte());
        System.out.println(in.readInt());
        System.out.println(in.readLong());
        System.out.println(in.readFloat());
        System.out.println(in.readDouble());
        System.out.println(in.readUTF());

        in.close();
    }
}